<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: pink;
        }

        #box {
            width: 900px;
            height: 63px;
            margin: 100px auto;
            background-color: #fff;
            position: relative;
        }

        #box ul {
            width: 100%;
            height: 100%;
            list-style: none;
            background: url("images/doubleOne.png") no-repeat right center;
            z-index: 1;
            position: absolute;
        }

        #box ul li {
            float: left;
            width: 88px;
            height: 63px;
            line-height: 63px;
            text-align: center;
            cursor: pointer;
        }

        #t_mall {
            background: url("images/tMall.png") no-repeat;
            width: 88px;
            height: 63px;
            position: absolute;
            left: 0;
            top: 0;
        }
    </style>
</head>

<body>
    <div id="box">
        <span id="t_mall"></span>
        <ul>
            <li>双11狂欢</li>
            <li>服装会场</li>
            <li>数码家电</li>
            <li>家具建材</li>
            <li>母婴童装</li>
            <li>手机会场</li>
            <li>美妆会场</li>
            <li>进口会场</li>
            <li>飞猪旅行</li>
        </ul>
    </div>
</body>
<script>

 // 1.获取标签
 var box = document.getElementById('box');
    var oul = box.children[1];//获取box的亲儿子 索引为1
    var list = oul.children;//获取ul的亲儿子 索引为1
    var tmall = box.children[0];
//    tmall.style.left = 100 + 'px';

    // 记录上一次点击的位置
    var temp = 0;

    // 2.添加事件
    for(var i = 0; i<list.length; i++){
        // 1.取出元素
        var ele = list[i];
        // 2.添加鼠标经过事件
        ele.onmouseover = function () {
            endX = this.offsetLeft;
        };
        ele.onclick = function () {
            temp = this.offsetLeft;
        };

    }
    // 3.当鼠标离开
    box.onmouseout = function () {
       endX = temp;
    };

    var beginX = 0;
    var endX = 0;
    setInterval(function () {
        beginX = beginX + (endX - beginX)/10;
        tmall.style.left = beginX + 'px';
    },10);




</script>
</html>